Skip to content

fix: hash UNet engine cache key so ONNX export path stays under Windows MAX_PATH#9

Merged
forkni merged 2 commits into
SDTD_040_beta_releasefrom
integ/maxpath-to-040
Jul 19, 2026
Merged

fix: hash UNet engine cache key so ONNX export path stays under Windows MAX_PATH#9
forkni merged 2 commits into
SDTD_040_beta_releasefrom
integ/maxpath-to-040

Conversation

@forkni

@forkni forkni commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Summary

Cherry-pick of 153669b from fix/unet-engine-path-maxpath (the head branch of open upstream PR dotsimulate#29) onto SDTD_040_beta_release, so the fix reaches our release/install line without waiting on upstream. That branch is left untouched; PR cumulo-autumn#29 stays open.

  • EngineManager.get_engine_path encoded every UNet build flag verbatim into the on-disk directory name. With sd-turbo + fp8 + static batch + pin_cache_frames + optlvl + resolution, the derived unet.engine.onnx path hit 263 chars and unet.engine.opt.onnx hit 267 — both over Windows' 260-char MAX_PATH.
  • The directory mkdir silently succeeded while torch.onnx.export's open(onnx_path, "wb") raised a bare FileNotFoundError, which the OOM-only fallback in wrapper.py doesn't catch, surfacing as "Acceleration has failed".
  • Fix: for EngineType.UNET only, hash the fully-assembled flag prefix (sha1, first 12 hex chars) — reusing the existing _lora_signature idiom — keeping model name, fp8, and resolution human-readable. Path drops from ~267 to ~132 chars. VAE/ControlNet naming is untouched (existing engines not invalidated); UNet engines rebuild once under the new hashed folder name. Adds a warning if a derived path would still approach MAX_PATH.

Test plan

  • python -m py_compile src/streamdiffusion/acceleration/tensorrt/engine_manager.py
  • pytest tests/unit/test_engine_path_length.py -v → 3 passed (path-length regression, determinism, no-collision)
  • End-to-end: sd-turbo + fp8: true + acceleration: tensorrt build reaches engine compilation instead of FileNotFoundError

…ws MAX_PATH

EngineManager.get_engine_path encoded every UNet build flag verbatim into the
on-disk directory name. With a realistic engine_dir (fp8 + static batch +
pin_cache_frames + optlvl + resolution), the folder grew to 246 chars, and the
derived unet.engine.onnx / unet.engine.opt.onnx paths hit 263/267 chars --
over Windows' 260-char MAX_PATH. Because the *directory* fit but the *file*
didn't, mkdir succeeded while torch.onnx.export's open(onnx_path, "wb") raised
FileNotFoundError, which wrapper.py's OOM-only fallback doesn't catch, so the
build failed with "Acceleration has failed: [Errno 2] No such file or
directory: ...unet.engine.onnx".

Fix: for EngineType.UNET only, hash the fully-assembled flag prefix (sha1,
first 12 hex chars) using the existing _lora_signature hashing idiom, keeping
model name + fp8 + resolution human-readable in the folder name. Cache-key
precision is unchanged (identical configs still hash identically, differing
configs still diverge) -- only the on-disk encoding is compacted, from ~267
chars down to ~132. VAE/ControlNet directory naming is untouched, so existing
VAE engines are not invalidated; UNet engines rebuild once under their new
hashed folder name. Also adds a belt-and-suspenders warning if a derived path
would still approach MAX_PATH (e.g. an unusually deep user engine_dir), and
casts the "filename" config lookup to str to keep the type checker precise
about self._configs' heterogeneous per-key value types.

Adds a regression test (test_engine_path_length.py) that reproduces the exact
crash-log config and asserts the derived .onnx / .opt.onnx paths stay under
MAX_PATH, plus determinism and no-collision checks.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
forkni added a commit that referenced this pull request Jul 19, 2026
)

SDTD_040_beta_release only had release.yml, so forkni-internal PRs targeting
it (e.g. #9) had no automated CI gate at all -- GitHub resolves pull_request
workflows from the base branch's copy, and this repo's Claude review workflow
lived only on SDTD_032_dev's branches list. Copies the workflow verbatim and
adds SDTD_040_beta_release to its branches filter so PRs into the release
line get the same review gate as PRs into dev.

This PR itself can't be CI-gated (the base branch doesn't have the workflow
until this merges) -- infra-only change, verified by YAML parse + diff review
against the working SDTD_032_dev copy.
@forkni
forkni merged commit 241597d into SDTD_040_beta_release Jul 19, 2026
1 check passed
@forkni
forkni deleted the integ/maxpath-to-040 branch July 19, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant